

import permision from "@/js_sdk/wa-permission/permission.js"

/**
 * 获取手机摄像头和图册权限
 * */
const cameraAuthority = () =>{
	return new Promise(async (rel,rej)=>{
		let camera = await permision.requestAndroidPermission("android.permission.CAMERA");//判断安卓是否给予摄像头权限
		let photoLibrary = await permision.requestAndroidPermission("android.permission.READ_EXTERNAL_STORAGE");//判断安卓是否给予相册权限
		console.log(camera,photoLibrary);
		if(camera == 0 || photoLibrary == 0){
			rej('请同时开启相机和相册的使用权限');
		}else if(camera == -1 || photoLibrary == -1){
			//永久拒绝
			rej(false)
		}else{
			rel();
		}
	})
}

/**
 * 限安卓
 * 是否打开了手机定位
 * */
const adressOpen = () =>{
	return permision.checkSystemEnableLocation();
}

/**
 * 限安卓
 * 获取位置信息权限
 * */
const adressAuthority = () =>{
	return new Promise(async (rel,rej)=>{
		let adress = await permision.requestAndroidPermission("android.permission.ACCESS_FINE_LOCATION");//判断安卓是否有获取位置信息权限
		if(adress == 0){
			rej('请开启定位权限');
		}else if(adress == -1){
			//永久拒绝
			rej(false)
		}else{
			rel();
		}
	})
}

/**
 * 限安卓
 * 获取拨打电话权限
 * */
const cellPhoneAuthority = () =>{
	return new Promise(async (rel,rej)=>{
		let adress = await permision.requestAndroidPermission("android.permission.CALL_PHONE");//拨打电话权限
		if(adress == 0){
			rej('请开启拨打电话权限');
		}else if(adress == -1){
			//永久拒绝
			rej(false)
		}else{
			rel();
		}
	})
}

/**
 * 跳转到手机开启权限的界面
 * */
const permissionSetting = () =>{
	permision.gotoAppPermissionSetting();
}

export{
	cameraAuthority,
	permissionSetting,
	adressAuthority,
	adressOpen,
	cellPhoneAuthority
}
